;
(function($) {
    $.fn.ace_widgets_type = function(options) {
        options = $.extend({
            // 事件类型
            oEvent: "click",
            maxLength: 3,
            // 取值后添加的目标
            // need like this #jobDialog
            addTarget: this,
            // 数据源路径
            dataType: "getJobName",
            oDataSource: "",
            // 是否多选
            isMulti: true,
            // 默认显示的文字提示
            thisText: "请选择职位名称",
            dialogId: "js_dialog_data",
            isSubstring: false,
            oWidth: 920,
            _typeName:null,
            dialogClose: function() {
            }
        },
        options || {});
        var $_dialogID = $("#" + options.dialogId);
        if($("#"+options.dialogId).size()>0) {
            $("#"+options.dialogId).remove();
        }
        // create Dialog
        // 没有创建一个
        $("<div id='" + options.dialogId
        + "' class='app_allDatabox_widgets'></div>").appendTo(
        "body");
        $_dialogID = $("#" + options.dialogId);
        var str_dialogBtnbar = '<div class="widgets_btnbox tar">'
        + '<button rel="area_ok" class="app_btn_f_v2 fb_14">确 定</button>'
        + '<button rel="area_shut" class="app_btn_b_v2 fb_hui">关 闭</button>'
        + '</div>';
        $_btnBar = $(str_dialogBtnbar);
        if (options.isMulti) {
            $_btnBar.appendTo($_dialogID);
        }
        var $_btnBar;
        var $_XML;
        var _dialogTitle = "";
        var $_selectArea = "";
        var _selectArray = [];
        var isHaveSec = true;
        if (options.maxLength == 1) {
            _dialogTitle = options.thisText + ",最多只能选择一项";

        } else {
            _dialogTitle = options.thisText + ",不能超过" + options.maxLength + "项";

        }
        // need jquery ui init
        $_dialogID
        .dialog({
            autoOpen: false,
            modal: true,
            width: options.oWidth,
            resizable: false,
            title: _dialogTitle,
            open: function() {
                // 打开前判断是否有选中的选项,第一次初始化的时候无数据
                // var _targetText=$(options.addTarget).attr("rel");
                // var _bigText=$(options.addTarget).attr("_bigid");

                /* 利用ID生成idText */
                var alldbid = $(options.addTarget).attr("ALLDBID");
                var alldbtext = $(options.addTarget).attr("ALLDBTEXT");
                if (!alldbid || alldbid=="" || alldbid == ".#" && alldbtext == ".#" || alldbid == "#" && alldbtext == "#") {

                } else {
                    var _targetText = "";
                    var _bigText = "";
                    // 取fristID and SecID
                    var _hasMinus = /(.+),$/i;
                    if (alldbid != undefined && alldbtext != undefined) {
                        alldbid = alldbid.substring(0,
                        alldbid.length - 1);
                        alldbtext = alldbtext.substring(0,
                        alldbtext.length - 1);
                        var alldbidArray = alldbid.split("#");
                        var _allIDArray=[];
                        var _optionStr = "";
                        for(var k=0;k<alldbidArray.length;k++) {
                            if (options.isMulti && isHaveSec==true) {
                                var group=alldbidArray[k].split(".");
                                var $_sec=$_XML.find("SecData[dbId='"+group[1]+"']");
                                var $_first=$_sec.closest("FirstType");
                                var secName=$_sec.attr("secName");
                                _optionStr +="<a secdbid='"+$_sec.attr("dbId")+"' firstdbid='"+$_first.attr("dbId")+"' " +
                                "parenttypeid='"+options.dataType+$_first.attr("id")+"' _sectext='"+secName+"'" +
                                "_firsttext='"+$_first.attr("Name")+"' href='javascript:void(0)' title='"+secName+"'"+
                                "class='widgets_a_b' id='check_"+options.dataType+"_"+$_first.attr("elementName")+"_sec_"
                                +$_sec.attr("secId")+"'>"+secName+"</a>";
                            } else {
                                //一级
                                var $_first=$_XML.find("FirstType[dbId='"+alldbidArray[k]+"']");
                                _optionStr += '<a firstdbid='
                                + $_first.attr("dbId")
                                + ' _firsttext='
                                + $_first.attr("Name")
                                + ' parenttypeid="'
                                + options.dataType+$_first.attr("Id")
                                + '" href="javascript:void(0)" title="'
                                + $_first.attr("Name")
                                + '" class="widgets_a_b" id="'
                                + "check_"+options.dataType+$_first.attr("Id") + '">'
                                + $_first.attr("Name") + '</a>';
                            }
                        }

                        $_dialogID.find(".widgets_box_a .common_box_selected").empty().append(_optionStr);

                        // 判断是一级要多选的，则打钩
                        if (options.isMulti && isHaveSec != true) {
                            $("#widgets_type_selectbox .common_box_selected .widgets_a_b").each( function() {
                                var _mulit_firstID = $(this).attr("parenttypeid");
                                $("#" + _mulit_firstID).attr("checked", true);

                            });
                        }

                    }

                }
                if ($_dialogID.find(".widgets_box_a .common_box_selected .widgets_a_b").length == 0) {
                    _noData();
                }
                //$_dialogID.dialog('option', 'position', 'center');
                $("select").css("visibility","hidden");
            },
            close: function() {
                $("select").css("visibility","visible");
                // 关闭dialog;
                if ($_dialogID.find(
                ".widgets_box_a .common_box_selected").find(
                ".widgets_a_b").length == 0) {
                    $(options.addTarget).removeAttr("rel");
                    $(options.addTarget).removeAttr("_bigid");
                    if (options.addTarget[0] && options.addTarget[0].tagName == "a") {
                        $(options.addTarget).html(
                        "<span>请选择" + options._typeName
                        + "类型</span>").css(
                        "text-align", "center");

                    }

                }
                if ((typeof(options.dialogClose) == 'function')) {
                    options.dialogClose();

                }

            }
        });

        // 全局的Dialog已经有了
        var $_dialogID = $("#" + options.dialogId);
        var _js_oType = options.dataType;
        // 接收data url,发起ajax
        function _getSource(url) {
            var _url = url;
            if($.data(document.body,url)!=undefined) {
                widgetsCallback($.data(document.body,url));
            } else {
                $.ajax({
                    type: "GET",
                    url: _url,
                    dataType: "xml",
                    cache: false,
                    beforeSend: function() {
                        $_dialogID.addClass("loading");
                    },
                    error: function(xml) {
                        jAlert("加载数据源失败，请重试", "温馨提示");

                    },
                    success: function(data) {
                        $.data(document.body,url,data);
                        widgetsCallback(data);
                    }
                })
            }
        }

        function widgetsCallback(data) {
            $_dialogID.removeClass("loading");
            $_XML = $(data);
            var _firstDom = "";
            var _hotDom="";
            var $_hotHtml;
            var $_hotDom=$_XML.find("SecData[isHot='true']");
            //有热门推荐的类型或者城市，则添加其热门的Dom结构
            if($_hotDom.size()>0) {
                _firstDom="<div class='ace_widgets_hotbar c p_tb_10' id='J_widgets_hotbar'><div class='ace_widgets_hot l'>"+$_hotDom.eq(0).attr("hotName")+"</div>";
                _hotDom="<div class='l widgets_hotbox'>";
                $_hotDom.each( function() {
                     var _firstdbid=$(this).attr("dbId")=='undefined'?$(this).attr("secId"):$(this).attr("dbId");
                     var _chkID=options.dataType+ "_"+ $(this).closest("FirstType").attr("elementName")+ "_sec_"+ $(this).attr("secId");
                     var _firstText=$(this).closest("FirstType").attr("Name");
                    _hotDom+='<span class="l widgets_hot_option"><label title="'+$(this).attr("secName")+ '" for="'+_chkID+'"><input type="checkbox" firstdbid="'+_firstdbid+'" secdbid="'+$(this).attr("secId")+'" _sectext="'+$(this).attr("secName")+'" id="'+_chkID+'" _firsttext="'+_firstText+'" />'+ $(this).attr("secName")+ '</label></span>';
                });
                _hotDom+="</div></div>";
                _firstDom+=_hotDom;
            }
            //进行一级的类型分组,根据数组类型进行分类
            if(options._firstSortName!=undefined) {
                //如果是选择城市类型，则添加其它城市的头。
                options.dataType=='getArea'?_firstDom+='<strong class="widgets_other_city c_b">其它城市</strong>':"";
                if(options.dataType=='getArea'){
                    var _widgetsCityArea="widgets_spec_hot";
                    var _widgetsSpecOpiton="widgets_spec_option";
                    var _widgetsFirstOption="widgets_city_option";
                }else{
                    var _widgetsCityArea="";
                    var _widgetsSpecOpiton="";
                    var _widgetsFirstOption="";
                }
                _firstDom+='<div class="app_widgets_firstParent'+_widgetsSpecOpiton+'">';
                for(var i=0;i<options._firstSortName.length;i++) {
                    _firstDom+='<div class="app_widgets_sortbox c"><div class="ace_widgets_sort l '+_widgetsCityArea+'">'+options._firstSortName[i]+'：</div><div class="widgets_option_box l '+_widgetsFirstOption+'">';
                    $_XML.find("FirstType[firstSortName='"+options._firstSortName[i]+"']").each( function() {
                        if (options.isMulti==true) {
                            _firstDom += '<span class="widgets_option"><label title="'+$(this).attr("Name")+'" for="'+ _js_oType+ $(this).attr("dbId")+ '"><input type="checkbox" _firstText='
                            + $(this).attr("Name")+ ' firstDBID='+ $(this).attr("dbId")+ ' id="'+ _js_oType+ $(this).attr("dbId")+ '">'+ $(this).attr("Name")+ '</label></span>';
                        } else {
                            //只有一级的数据，无二级
                            _firstDom += '<span class="widgets_option"><label title="'+$(this).attr("Name")+'"><input type="radio" _firstText='
                            + $(this).attr("Name") + ' firstDBID='+ $(this).attr("dbId") + ' id="' + _js_oType+ $(this).attr("dbId")+ '">'+ $(this).attr("Name")+ '</label></span>';
                        }
                    });
                    _firstDom+="</div></div>";
                }
                _firstDom+="</div>";
            }else{
              //没有一级类型的数据划分，则调用其结构
              $_XML.find("FirstType").each( function() {
                         //多选情况
                        if (options.isMulti==true) {
                            _firstDom += '<span class="widgets_option"><label title="'+$(this).attr("Name")+'"><input type="checkbox" _firstText='
                            + $(this).attr("Name")+ ' firstDBID='+ $(this).attr("dbId")+ ' id="'+ _js_oType+ $(this).attr("dbId")+ '">'+ $(this).attr("Name")+ '</label></span>';
                        } else {
                            //只有一级的数据，无二级，单选情况
                            _firstDom += '<span class="widgets_option"><label title="'+$(this).attr("Name")+'"><input type="radio" _firstText='
                            + $(this).attr("Name") + ' firstDBID='+ $(this).attr("dbId") + ' id="' + _js_oType+ $(this).attr("dbId")+ '">'+ $(this).attr("Name")+ '</label></span>';
                        }
                    });
            }
            _addDom(_firstDom);
            //数据一级事件绑定
            var $_allChk=$("#_firstDom .widgets_option").find("label").find("input");
            $("#_firstDom .widgets_option").find("label").find("input").bind("click", function(e) {
                var $_ck = $(this);
                var $_parent = $(this).parent();
                var $_option=$(this).closest(".widgets_option");
                var $_allOption=$("#_firstDom").find(".widgets_option");
                var isHaveSec = $_XML.find("SecData").size() >= 1 ? true: false;
                // 添加二级绑定
                // 有二级数据，给它绑定事件
                var _currentClass=options.isMulti&&isHaveSec==true?"app_widgets_selected":"app_widgets_current";
                isHaveSec = $_XML.find("SecData").size() >= 1 ? true: false;
                if (options.isMulti) {
                    var $_firstChecked = $_ck;
                    // $_firstChecked[0].checked==true?$_firstChecked[0].checked=false:$_firstChecked[0].checked=true;
                    if (isHaveSec) {
                        // 点击了自己打钩，其它关闭
                        $_allChk.attr("checked", false);
                        $_ck.attr("checked",true);
                        var _txtId = $_ck.attr("firstdbid");
                        _txtId = _txtId.match(/(\d+)/g);
                        var _secDom = "";
                        var _firstText = $_parent.text();
                        // 构建二级Dom数据
                        $_XML.find("FirstType[dbId='"+_txtId+"']").find("SecData").each( function() {
                            var _fistDBID = $_XML.find("FirstType[dbId='"+_txtId+"']").attr("dbId");
                            var _firstText = $_XML.find("FirstType[dbId='"+_txtId+"']").attr("Name");
                            var _secText = $(this).attr("secName");
                            var _parentElementName = $_XML.find("FirstType[dbId='"+_txtId+"']").attr("elementName");
                            var _secId = options.dataType+ "_"+ _parentElementName+ "_sec_"+ $(this).attr("secId");
                            var _parentID = options.dataType+ ($_XML.find("FirstType[dbId='"+_txtId+"']").attr("Id"));
                            var _secDBID = $(this).attr("dbId");
                            if(options.maxLength==1) {
                                _secDom += '<dd><label title="'+_secText+'" for="' + _secId+ '"><input type="radio" _secText='+ _secText+' _firstText='+ _firstText+ ' id="' + _secId+ '" parentTypeID="'+ _parentID + '" firstDBID='+ _fistDBID+ ' secDBID='+ _secDBID+ '><span>' + $(this).attr("secName")+ '</span></label></dd>';
                            } else {
                                _secDom += '<dd><label title="'+_secText+'" for="' + _secId+ '"><input type="checkbox" _secText='
                                + _secText
                                + ' _firstText='
                                + _firstText
                                + ' id="'
                                + _secId
                                + '" parentTypeID="'
                                + _parentID
                                + '" firstDBID='
                                + _fistDBID
                                + ' secDBID='
                                + _secDBID
                                + '><span>'
                                + $(
                                this)
                                .attr(
                                "secName")
                                + '</span></label></dd>';
                            }
                        });
                        $("#_secDom").empty();
                        $(_secDom).appendTo($("#_secDom")[0]);
                        //$('<dt class="app_widgets_titlebar">请选择'+ _firstText+ '二级选项</dt>').insertBefore($("#_secDom dd").eq(0));
                        $("#_secDom").show();
                        $("#J_widgets_secdom").show();
                        $("#J_widgets_secdom").insertAfter($(this).closest(".app_widgets_sortbox"));
                        //只有一个dd，则不加
                              if(options.isMulti&&isHaveSec&&$("#J_widgets_secdom").find("dd").size()==1){
                                  $_allOption.removeClass(_currentClass);
                                  $("#J_widgets_secdom").hide();
                            }else{
                                 $_allOption.removeClass(_currentClass);
                                 $_option.addClass(_currentClass);
                            }
                                    // 二级Dom节点数据绑定,:checkbox改成input
                                    $("#_secDom dd").find("label").find("input").bind("click", function() {
                                        var $_ck = $(this);
                                        var $_text = $(this).next("span");
                                        var $_selected = $("#widgets_type_selectbox").find(".common_box_selected").eq(0);
                                        if(options.maxLength!=1) {
                                            //二组多选情况,单选则不提示，直接替换掉其内容
                                            if ($_ck[0].checked && $_selected.find(".widgets_a_b").size() + 1 > options.maxLength) {
                                                jAlert("最多只能选择"+ options.maxLength+ "项，请先删除不需要的选项",
                                                "温馨提示");
                                                $_ck.attr("checked", false);
                                                return;
                                            }
                                        }
                                        var _secText = $_text.text();
                                        var _selectID = $_ck.attr("id");
                                        if ($_ck.length > 0) {
                                            // this代表input
                                            var tempMax = options.maxLength;
                                            var _id = $_ck.attr("id");
                                            var _parentTypeID = $_ck.attr("parenttypeid");
                                            var _text = $_text.text();
                                            var _selectedStr = '<a id="'
                                            + "check_"+ _id+ '" class="widgets_a_b" title="'+ _text+ '" href="javascript:void(0)" parentTypeID='+ _parentTypeID+ '>'+ _text+ '</a>';
                                            var $_selected = $("#widgets_type_selectbox").find(".common_box_selected").eq(0);
                                            _clickCheckBox($(this).parent()[0], options.maxLength);
                                            // 执行检查
                                            // _checkRight();
                                            _selectArray = [];
                                            $("#_secDom dd").find("input").each( function() {
                                                _selectArray.push($(this).attr("id"));
                                            })
                                        }
                                        return ;
            
                                    });
                        
                        /* 如选中列表中有的，二级要选中 */
                        if ($_dialogID.find(".widgets_box_a .common_box_selected .widgets_a_b").size() > 0) {
                            $_dialogID.find(".widgets_box_a .common_box_selected .widgets_a_b").each( function() {
                                var _secChkID = $(this).attr("id").substring(6,
                                $(this).attr("id").length);
                                $("#"+ _secChkID).attr("checked", true);
                            })
                        } else {
                            _noData();
                        }

                        //添加如果是多选的，但是二级只有一条数据则直接触发点击;
                        if($("#_secDom dd").size()==1) {
                            $("#_secDom dd").find("input").trigger("click");
                            $("#_secDom").hide();
                        }
                    } else {
                        // 没有二级，但是多选情况
                        var firstdbid = $_ck.attr("firstdbid");
                        var _text = $_ck.attr("firsttext");
                        var _id =$_ck.attr("id");
                        var _parentTypeID = $_ck.attr("id");
                        if ($_ck.length > 0) {
                            var _selectedStr = '<a id="'+ "check_"+ _id+ '" class="widgets_a_b" title="'+ _text+ '" href="javascript:void(0)" parentTypeID='+ _parentTypeID+ '>'+ _text+ '</a>';
                            var $_selected = $("#widgets_type_selectbox").find(".common_box_selected").eq(0);
                            _clickCheckBox($(this).parent()[0],options.maxLength);
                          }
                    }
                    //$_dialogID.dialog("option", "position", "center");

                } else {
                    // 单选模式
                    $_parent.parent().siblings().find("input").attr("checked", false);
                    $_ck[0].checked = true;
                    $_parent.parent().siblings().find(":radio").attr("checked", false);
                    _clickRadioBox(this);
                    $_dialogID.find("#widgets_type_selectbox").hide();
                    $_dialogID.find(".widgets_btnbox").hide();
                    // 加值
                    _resetValue();
                    $_dialogID.dialog('close');
                    return false;
                }
            });
            /*------------------------事件区-----------------------------------------------*/
            // checkbox
             $_dialogID.dialog('open');
            //非地区类添加隔行变色
            if(options.dataType!="getArea"){
              $("#_firstDom .app_widgets_sortbox:even").addClass("ace_widgets_bg");
             }
        }
        //有热门城市或者热门推荐的二级选项数据
        function _hotData(){
            var $_hotChk=$("#J_widgets_hotbar :input");
            
            $_hotChk.bind("click",function(){
                 var $_label=$(this).closest("label");
                 _clickCheckBox($_label, options.maxLength);
            });
        }

        function _noData() {
            //$_dialogID.find("input").attr("checked", false);
            $_dialogID.find(".common_box_selected").html(
            "暂时未选择" + options._typeName);

        }

        function _toggleChecked(checkObj) {
            var _checkObj = $(checkObj)[0];
            _checkObj.checked == true ? false: true;
            return false;

        }

        function _checkRight() {
            // 如果上面selected有的选项，父级则要添加选中按纽
            var $_selectedBox = $_dialogID
            .find(".widgets_box_a .common_box_selected");
            var $_selected_option = $_selectedBox.find(".widgets_a_b");
            $_selected_option.each( function() {
                // 父级先全部取消
                $("#" + $(this).attr("parenttypeid")).attr("checked", false);
                var _parentID = $(this).attr("parenttypeid");
                // 不选父级的checkbox
                // $("#"+_parentID).attr("checked",true);
                // 去除check_;
                var _optionID = $(this).attr("id");
                _optionID = _optionID.substring(6, _optionID.length);
                /* 二级数据的checkbox要选中 */
                ;
                $("#" + _optionID).attr("checked", true);

            })
            if ($_selected_option.size() == 0) {
                _noData();

            }

        }

        // 单选形式的添加
        function _clickRadioBox(obj) {
            $_obj = $(obj);
            // obj代表label
            var _parentTypeID = $_obj.attr("id");
            var _text = $_obj.parent().text();
            var _firstDBID = $_obj.attr("firstdbid");
            var _firstDBText = $_obj.attr("_firsttext");
            var _selectedStr = '<a id="' + "check_" + _parentTypeID
            + '" class="widgets_a_b" title="' + _text
            + '" href="javascript:void(0)" firstDBID=' + _firstDBID
            + ' _firstDBText="' + _firstDBText + '" parentTypeID="'
            + _parentTypeID + '">' + _text + '</a>';
            var $_selected = $("#widgets_type_selectbox").find(
            ".common_box_selected").eq(0);
            $_selected.empty();
            $_selected.append(_selectedStr);

        }
        //给选中区域的选项给值操作
        function _clickCheckBox(obj, tempMax) {
            var _id = $(obj).find("input").attr("id");
            var _text = $(obj).text();
            var _firstText = $(obj).find("input").attr("_firsttext");
            var _fistDBID = $(obj).find("input").attr("firstDBID");
            var _parentTypeID=options.dataType+_fistDBID;
            if (options.isMulti && isHaveSec == true) {
                var _secText = $(obj).find("input").attr("_sectext");
                var _secDBID = $(obj).find("input").attr("secDBID");
                var _selectedStr = '<a id="' + "check_" + _id
                + '" class="widgets_a_b" title="' + _text
                + '" href="javascript:void(0)" _firstText='
                + _firstText + ' _secText=' + _secText
                + ' parentTypeID=' + _parentTypeID + ' firstDBID='
                + _fistDBID + ' secDBID=' + _secDBID + '>' + _text
                + '</a>';
            } else {
                var _selectedStr = '<a id="' + "check_" + _id
                + '" class="widgets_a_b" title="' + _text
                + '" href="javascript:void(0)" _firstText='
                + _firstText + ' parentTypeID=' + _parentTypeID
                + ' firstDBID=' + _fistDBID + '>' + _text + '</a>';

            }
            var $_selected = $("#widgets_type_selectbox").find(
            ".common_box_selected").eq(0);
            $(obj).find("input").each( function(e) {
                var _checkId = "check_" + $(this).attr("id");
                //二级隐藏只有一条数据直接选中
                if(options.maxLength!=1&&$("#_secDom dd").size()==1&&isHaveSec) {
                    this.checked=true;
                }
                if (!this.checked&&options.maxLength!=1) {
                    // 原来中，切到不中
                    //$(this).attr("checked", false);
                    $_selected.find(".widgets_a_b[id="+ _checkId + "]").remove();
                    // 删除没有了，显示请选择数据
                    if ($_selected.find(".widgets_a_b").size() == 0) {
                        $_selected.html("请选择"+ options._typeName + "类型");
                    }

                } else {
                    // 原来不中，切到选中
                    var _hasCheckNum = $_selected.find(".widgets_a_b").size() + 1;
                    //$(this).attr("checked", true);
                    // 有了则不加选中标签
                    if ($_selected.find(".widgets_a_b[id="+ _checkId + "]").length > 0) {
                        return false;
                    } else {
                        if ($_selected.find(".widgets_a_b").size() == 0) {
                            $_selected.html("");
                        }
                        // 没有则添加标签
                        if (($_selected.find(".widgets_a_b").size() + 1) <= tempMax) {
                            $(_selectedStr).appendTo($_selected);

                            //二级单选情况要选中当前的radio.
                            if(options.maxLength==1&&isHaveSec==true) {
                                $(this).attr("checked", true);
                            }
                        } else {
                            if(options.maxLength==1&&isHaveSec==true) {
                                $_selected.empty();
                                $(_selectedStr).appendTo($_selected);
                                $(this).attr("checked", true);
                                $(this).parents("dd").siblings("dd").find("input").attr("checked",false);
                            } else {
                                $(this).attr("checked", false);
                                jAlert("最多只能选择" + tempMax + "项", "温馨提示");
                                return false;
                            }
                        }

                    }

                }

            })
            // 执行检查
            // _checkRight();
            if (options.isMulti && isHaveSec == true) {
                _selectArray = [];
                $("#_secDom dd").find("input").each( function() {
                    _selectArray.push($(this).attr("id"));

                })
            }

        }

        function _addDom(temp_dataDom) {
            if (options.isMulti && isHaveSec == true) {
                    var _conentDom = '<div id="_allDataBox"><h3 id="widgets_type_selectbox" class="widgets_box_a">'
                    + '<strong class="f_b type_title">当前已选择'
                    + options._typeName
                    + '：</strong>'
                    + '<span class="common_box_selected"></span>'
                    + '</h3><div id="widgets_area_content" class="widgets_content_a">'
                    + '<div id="_firstDom" class="c m_t_8">'
                    + '<h4 class="app_widgets_titlebar">'
                    + options.thisText
                    + '</h4>'
                    + temp_dataDom
                    + '</div>'
                    + '<div id="J_widgets_secdom" class="widgets_secdom"><dl id="_secDom" class="c m_12 hidden app_widgets_data">'
                    + '<h4>请选择二级类别选项</h4>'
                    + '<span class="widgets_option"><input type="checkbox" id="" aid=""><label>北京</label></span>'
                    + '</dl></div>' + '</div>' + '</div>';
    
                } else {
                    var _conentDom = '<div id="_allDataBox"><h3 id="widgets_type_selectbox" class="widgets_box_a">'
                    + '<strong class="f_b type_title">当前已选择'
                    + options._typeName
                    + '：</strong>'
                    + '<span class="common_box_selected"></span>'
                    + '</h3><div id="widgets_area_content" class="widgets_content_a">'
                    + '<div id="_firstDom" class="c m_t_8"><div class="">'
                    + '<h4 class="app_widgets_titlebar">'
                    + options.thisText
                    + '</h4>'
                    + temp_dataDom
                    + '</div></div>' + '</div>' + '</div>';
    
                }
            if ($("#_allDataBox").length > 0) {
                $("#_allDataBox").remove();

            }
            if (options.isMulti) {
                $(_conentDom).insertBefore($_dialogID.find(".widgets_btnbox"));

            } else {
                $(_conentDom).appendTo($_dialogID[0]);

            }
            // 无数据的时候，提示没有选择任何数据;
            if ($("#widgets_type_selectbox .common_box_selected").find("a")
            .size() == 0) {
                $("#widgets_type_selectbox .common_box_selected").show().html(
                "暂时未选择" + options._typeName );

            }
            ;
            //并且有推荐的热门城市或者推荐类型
            _hotData();
        }

        // 目标元素点击打开Dialog
        $(this).bind(options.oEvent, function() {
            // click的时候，根据数据类型的时候添加数据,往dialog里添加DOM数据结构
            var host = "/action?UICompnentService=0&action=";
            var _url_out = options.oDataSource;
            var _url = {
                getJobName: "JobType",
                getEnterpriseScale: "",
                getDiploma: "Diplomas",
                getPayment: "Payment",
                getWorkDomain: "Domains",
                getEnterpriseType: "EnterpriseType",
                getArea: "Areas",
                getDisciplineType: "DisciplineType",
                getJobType: "SimpleJobType"

            };
            //定义第一级的数据类型划分
            var _firstSort_template= {
                getArea: {
                    firstSortName:['华东地区','华南地区','华中地区','华北地区','西北地区','西南地区','东北地区','港澳台海外']
                },
                getJobName:{
                    firstSortName:['计算机/互联网/通讯/电子','会计/金融/银行/保险','生物/制药/医疗/护理','销售/客服/技术支持','广告/市场/媒体/艺术','生产/营运/采购/物流','房地产/建筑','人事/行政/高级管理','咨询/法律/教育/科研','服务业','公务员/翻译/其它']
                },
                getDisciplineType:{
                    firstSortName:['计算机/互联网/通讯/电子','会计/金融/银行/保险','生物/制药/医疗/护理','销售/客服/技术支持','广告/市场/媒体/艺术','生产/营运/采购/物流','房地产/建筑','人事/行政/高级管理','咨询/法律/教育/科研','服务业','公务员/翻译/其它']
                }
            };
            switch (_js_oType) {
                case 'getJobName':
                    options._typeName = "职位名称";
                     options._firstSortName=_firstSort_template.getJobName.firstSortName;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getJobName);
                    break;
                case 'getEnterpriseScale':
                    options._typeName = "企业规模";
                    isHaveSec=false;;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getEnterpriseScale);
                    break;
                case 'getDiploma':
                    options._typeName = "最高学历";
                    isHaveSec=false;;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getDiploma);
                    break;
                case 'getPayment':
                    options._typeName = "年薪范围";
                    isHaveSec=false;;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getPayment);
                    break;
                case 'getWorkDomain':
                    options._typeName = "行业";
                    isHaveSec=false;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getWorkDomain);
                    break;
                case 'getEnterpriseType':
                    options._typeName = "企业性质";
                    isHaveSec=false;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getEnterpriseType);
                    break;
                case 'getArea':
                    //是个第一级名称数组
                    options._firstSortName=_firstSort_template.getArea.firstSortName;
                    options._typeName = options._typeName ? options._typeName:"地点";
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getArea);
                    break;
                case 'getDisciplineType':
                    options._typeName = "专业类型";
                    options._firstSortName=_firstSort_template.getDisciplineType.firstSortName;
                    isHaveSec=false;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;
                    }
                    _getSource(host + _url.getDisciplineType);
                    break;
                case 'getJobType':
                    options._typeName = "职位类型";
                    isHaveSec=false;
                    if (_url_out != "") {
                        _getSource(_url_out);
                        break;

                    }
                    _getSource(host + _url.getJobType);
                    break;

            }

        });
        // 拥有二级的数据
        //
        function _resetValue() {
            if ($_dialogID.find(".common_box_selected .widgets_a_b").size() != 0) {
                var $_allSelected = $_dialogID
                .find(".common_box_selected .widgets_a_b");
                var _joinText = "";
                var _allDbText = "";
                var _allDbID = "";
                $_allSelected.each( function() {
                    _joinText += $(this).text() + "+";
                    if (options.isMulti) {
                        // checkbox多个类型
                        if (isHaveSec == true) {
                            _allDbID += $(this).attr("firstdbid") + "."
                            + $(this).attr("secdbid") + "#";
                            _allDbText += $(this).attr("_firsttext") + "."
                            + $(this).attr("_sectext") + "#";

                        } else {
                            _allDbID += $(this).attr("firstdbid") + "#";
                            _allDbText += $(this).attr("_firsttext") + "#";

                        }

                    } else {
                        // radio type
                        _allDbID += $(this).attr("firstdbid") + "#";
                        _allDbText += $(this).attr("_firstdbtext") + "#";

                    }

                })
                if (options.isSubstring) {
                    if (_joinText.length > 13) {
                        _joinText = _joinText.substring(0, 13) + "...";

                    }

                }
                var _strExp = /(.+)\+$/i;
                var _hasjia = _strExp.test(_joinText);
                if (_hasjia) {
                    _joinText = _joinText.substring(0, _joinText.length - 1)

                }
                if ($(options.addTarget)[0].tagName.toLowerCase() == "input") {
                    $(options.addTarget).val(_joinText);

                } else {
                    $(options.addTarget).html("<span>" + _joinText + "</span>");
                    $(options.addTarget).css("text-align", "center");

                }
                // 有值添加数据库value;
                $(options.addTarget).attr("ALLDBID", _allDbID);
                $(options.addTarget).attr("ALLDBTEXT", _allDbText);

            } else {
                //这里属性名小写为了解决IE8 使用大写无法删除属性的问题
                $(options.addTarget).removeAttr("alldbid");
                $(options.addTarget).removeAttr("alldbtext");
                if ($(options.addTarget)[0].tagName.toLowerCase() == "input") {
                    $(options.addTarget).val("请选择" + options._typeName);

                } else {
                    $(options.addTarget).html(
                    "<span>请选择" + options._typeName + "</span>");

                }

            }
            // 添加属性
            if ($_allSelected != undefined) {
                var _selectOptionStr = "";
                var _selectOpitonStr_big = "";
                $_allSelected.each( function() {
                    _selectOptionStr += $(this).attr("id") + ",";
                    _selectOpitonStr_big += $(this).attr("parenttypeid") + ",";

                });
                $(options.addTarget).attr("rel", _selectOptionStr);
                $(options.addTarget).attr("_bigID", _selectOpitonStr_big);

            }

        }

        // dialog中的确认按纽关闭dialog
        var $_dialog_shut_ok = $_dialogID.find(".app_btn_f_v2");
        $_dialog_shut_ok.live("click", function() {
            _resetValue();
            $_dialogID.dialog('close');

        });
        var $_dialog_shut_b = $_dialogID.find(".app_btn_b_v2")
        $_dialog_shut_b.live("click", function() {
            $_dialogID.dialog('close');

        })
        /* 选中的去除selected 去除代码 */
        $("#" + options.dialogId).find(".common_box_selected .widgets_a_b").live("click", function() {
            // new add
            var parenttypeid=$(this).attr("parenttypeid");
            if (options.isMulti && isHaveSec) {
                var _checkAid = $(this).attr("id").substring(6,$(this).attr("id").length);

            } else {
                var _checkAid = $(this).attr("parenttypeid");

            }
            $("#" + _checkAid).attr("checked", false);
            if($("#"+parenttypeid).size()>0){
                $("#"+parenttypeid).attr("checked", false);
            }
            $(this).remove();
            // 执行检查
            // _checkRight();
            if ($_dialogID
            .find(".widgets_box_a .common_box_selected .widgets_a_b").length == 0) {
                _noData();

            }

        });
    }
})(jQuery);
$.fn.getJobName = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getJobName",
        oDataSource: "",
        // 是否多选
        isMulti: true,
        // 默认显示的文字提示
        thisText: "请选择职位名称",
        dialogId: "js_dialog_jobName",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getEnterpriseType = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getEnterpriseType",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择企业性质",
        dialogId: "js_dialog_enterpriseType",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getDiploma = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 1,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getDiploma",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择学历",
        dialogId: "js_dialog_diplomas",
        isSubstring: false,
        oWidth:660,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getPayment = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getPayment",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择薪酬",
        dialogId: "js_dialog_payment",
        isSubstring: false,
        oWidth: 680,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getWorkDomain = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getWorkDomain",
        oDataSource: "",
        // 是否多选
        isMulti: true,
        // 默认显示的文字提示
        thisText: "请选择工作行业",
        dialogId: "js_dialog_workDomain",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getArea = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        oWidth:800,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getArea",
        oDataSource: "",
        // 是否多选
        isMulti: true,
        // 默认显示的文字提示
        thisText: "请选择地区",
        dialogId: "js_dialog_areas",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getDisciplineType = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getDisciplineType",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择专业类型",
        dialogId: "js_dialog_disciplineType",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getEnterpriseScale = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getEnterpriseScale",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择企业规模",
        dialogId: "js_dialog_enterpriseScale",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    return this.each( function() {
        $(this).ace_widgets_type(options);

    })
};
$.fn.getJobType = function(options) {
    options = $.extend({
        // 事件类型
        oEvent: "click",
        maxLength: 3,
        // 取值后添加的目标
        // need like this #jobDialog
        addTarget: this,
        // 数据源路径
        dataType: "getJobType",
        oDataSource: "",
        // 是否多选
        isMulti: false,
        // 默认显示的文字提示
        thisText: "请选择职位类型",
        dialogId: "js_dialog_simpleJobType",
        isSubstring: false,
        dialogClose: function() {
        }
    },
    options || {});
    $(this).ace_widgets_type(options);

};